import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutterapp/config.dart';
// import 'package:flutterapp/page/utils/dio_http.dart';

Future<String> uploadimages(List<File> files, BuildContext context) async {
  if (null == files) return Future.value('');
  if (0 == files.length) return Future.value('');
  //var fromData = FormData();
  var imgstr = "";
  for (int i = 0; i < files.length; i++) {
    // fromData.files.add(MapEntry(
    //     "file", await MultipartFile.fromFile(files[i].path.toString())));

    FormData formdata = FormData.fromMap({
      "files": await MultipartFile.fromFile(files[i].path, filename: 'images'),
      'scene': 'other',
    });

    Dio dio = new Dio();
    var respone = await dio.post<String>(
        Config.BaseUrl + '/flutter/uploadPictures',
        data: formdata);
    imgstr += respone.toString() + ",";
  }

  return Future.value(imgstr.toString());

  //fason
  // var res = await DioHttp.of(context).postFormData(url, fromData, token);
  // var data = json.decode(res.toString())['body'];
  // String images = List<String>.from(data).join('|');
}

class UploadImages extends StatelessWidget {
  const UploadImages({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
